import { createStore } from "vuex";
import skin from "./modules/skin";
import user from "./modules/user";
import createPersistedState from 'vuex-persistedstate';


export default createStore({
  modules: {
    skin,
    user
  },
  getters: {
    bgColor: (state) => state.skin.bgColor,
    token: (state) => state.user.token,
    username: (state) => state.user.username,
    account: (state) => state.user.account,
    routes: (state) => state.user.routes,
    sidebar: (state) => state.user.sidebar,
    id: (state) => state.user.id,
  },
  plugins: [
    createPersistedState({
      key: 'myAccount', // 自定义存储键名
      paths: ['user.token', 'user.username', 'user.account', 'user.sidebar', 'user.roles', 'user.id', 'skin'], // 指定要持久化的模块和属性
      storage: window.localStorage, // 使用 localStorage
    }),
  ],
});
